package com.tiantai.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tiantai.common.annotation.Log;
import com.tiantai.common.core.controller.BaseController;
import com.tiantai.common.core.domain.AjaxResult;
import com.tiantai.common.enums.BusinessType;
import com.tiantai.system.domain.TeaPrevention;
import com.tiantai.system.service.ITeaPreventionService;
import com.tiantai.common.utils.poi.ExcelUtil;
import com.tiantai.common.core.page.TableDataInfo;

/**
 * 虫情防治措施Controller
 * 
 * @author ruoyi
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/system/prevention")
public class TeaPreventionController extends BaseController
{
    @Autowired
    private ITeaPreventionService teaPreventionService;

    /**
     * 查询虫情防治措施列表
     */
    @PreAuthorize("@ss.hasPermi('system:prevention:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaPrevention teaPrevention)
    {
        startPage();
        List<TeaPrevention> list = teaPreventionService.selectTeaPreventionList(teaPrevention);
        return getDataTable(list);
    }

    /**
     * 导出虫情防治措施列表
     */
    @PreAuthorize("@ss.hasPermi('system:prevention:export')")
    @Log(title = "虫情防治措施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaPrevention teaPrevention)
    {
        List<TeaPrevention> list = teaPreventionService.selectTeaPreventionList(teaPrevention);
        ExcelUtil<TeaPrevention> util = new ExcelUtil<TeaPrevention>(TeaPrevention.class);
        util.exportExcel(response, list, "虫情防治措施数据");
    }

    /**
     * 获取虫情防治措施详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:prevention:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teaPreventionService.selectTeaPreventionById(id));
    }

    /**
     * 新增虫情防治措施
     */
    @PreAuthorize("@ss.hasPermi('system:prevention:add')")
    @Log(title = "虫情防治措施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaPrevention teaPrevention)
    {
        return toAjax(teaPreventionService.insertTeaPrevention(teaPrevention));
    }

    /**
     * 修改虫情防治措施
     */
    @PreAuthorize("@ss.hasPermi('system:prevention:edit')")
    @Log(title = "虫情防治措施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaPrevention teaPrevention)
    {
        return toAjax(teaPreventionService.updateTeaPrevention(teaPrevention));
    }

    /**
     * 删除虫情防治措施
     */
    @PreAuthorize("@ss.hasPermi('system:prevention:remove')")
    @Log(title = "虫情防治措施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teaPreventionService.deleteTeaPreventionByIds(ids));
    }
}
